import json

import requests

# # 三种获取响应的方式
# url = 'http://httpbin.org/get?name=wert'
# response = requests.get(url, params={'age':21, 'addr':'henan'}, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0'
#                                       })
# if response.status_code == 200:
#     response_bytes = response.content
#     response_str = response_bytes.decode('utf-8')
#     response_json = json.loads(response_str)
#     print(response_json['args'], response_json['headers']['User-Agent'])
#
#     response_text = response.text
#     response_json = json.loads(response_text)
#     print(response_json['args'], response_json['headers']['User-Agent'])
#
#     response_json = response.json()
#     print(response_json['args'], response_json['headers']['User-Agent'])


# url = 'http://httpbin.org/post?'
# response = requests.post(url, data={'name':'wert', 'age':23, 'addr':'henan'}, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0'
#                                        })
# if response.status_code == 200:
#     print(response.text)



# url = 'http://httpbin.org/post?'
# response = requests.post(url, json={'name':'wert', 'age':23, 'addr':'henan'}, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0',})
# if response.status_code == 200:
#     response_json = response.json()
#     print(response_json, response_json['headers']['User-Agent'])

url = 'https://t12.baidu.com/it/u=1055925850,278158059&fm=30&app=106&f=JPEG?w=312&h=208&s=FD84CA11D589594F1E5885C30300E0BB'
response = requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0',})
if response.status_code == 200:
    response_bytes = response.content
    with open('static/1.jpg', 'wb') as f:
        f.write(response_bytes)